from django.conf import settings
from django.db import models
from django.utils.translation import gettext_lazy as _


class FlavorTag(models.Model):
    name = models.CharField(_('标签名称'), max_length=200, null=True)
    is_bad = models.BooleanField(_('负面标签'), default=False)

    objects = models.Manager()

    class Meta:
        ordering = ['id']
        verbose_name = _('风味标签')
        verbose_name_plural = _('风味标签')

    def __str__(self):
        return "{0}".format(self.name)


class RateRecord(models.Model):
    pack_batch = models.ForeignKey(
        'oa.PackBatch',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        verbose_name=_('灌装批次')
    )
    product_batch = models.ForeignKey(
        'oa.ProductBatch',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        verbose_name=_('生产批次')
    )
    product_package = models.ForeignKey(
        'oa.ProductPackage',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        verbose_name=_('产品')
    )
    product_name = models.ForeignKey(
        'oa.ProductName',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        verbose_name=_('产品名称')
    )
    record_datetime = models.DateTimeField(_('品饮时间'), null=True)
    aroma = models.TextField(_('香气'), null=True, max_length=2000)
    flavor = models.TextField(_('味道'), null=True, max_length=2000)
    appearance = models.TextField(_('外观'), null=True, max_length=2000)
    feeling = models.TextField(_('口感'), null=True, max_length=2000)
    overall = models.TextField(_('整体表现'), null=True, max_length=2000)
    notes = models.TextField(_('其他备注'), null=True, blank=True, max_length=2000)
    flavor_tags = models.ManyToManyField(
        FlavorTag,
        blank=True,
        verbose_name=_('风味标签')
    )
    created_by = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
        verbose_name=_('创建人'),
        related_name='rate_record_created_by',
    )
    updated_by = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
        verbose_name=_('更新人'),
        related_name='rate_record_updated_by',
    )
    datetime_created = models.DateTimeField(_('创建时间'), auto_now_add=True)
    datetime_updated = models.DateTimeField(_('更新时间'), auto_now=True)

    objects = models.Manager()

    class Meta:
        ordering = ['-id']
        verbose_name = _('品鉴记录')
        verbose_name_plural = _('品鉴记录')

    def __str__(self):
        return "{0}".format(self.pack_batch)

